package ext.tianma.bom.service;

import org.json.JSONException;
import org.json.JSONObject;

import ext.tianma.bom.eco.BOMHelp;

/**
 * 用于BOM批量变更
 * @author Administrator
 *
 */
public class TMECOUtil {
	public static String username = "TIANMA";
	public static String passwerd = "TIANMA";
	public static String errorStatus = "failed";
	public static String correctStatus = "success";
	public static String errorMessage = "用户名或密码不正确";
	public static String errorData = "请求数据格式不正确";
	public static String errorUpdateMSG = "操作失败";

	public static String userValidate(String name, String pwd) {
		if (BOMHelp.isNullOrEmpty(name) || BOMHelp.isNullOrEmpty(pwd)
				|| !username.equals(name) || !passwerd.equals(pwd)) {
			JSONObject obj = new JSONObject();
			try {
				obj.put("status", errorStatus);
				obj.put("message", errorMessage);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return obj.toString();
		}
		return "";
	}

	/**
	 * 请求数据格式不正确
	 * 
	 * @return
	 */
	public static String errorRequestMessage() {
		JSONObject obj = new JSONObject();
		try {
			obj.put("status", errorStatus);
			obj.put("message", errorData);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj.toString();
	}
	/**
	 * 操作失败
	 * 
	 * @return
	 */
	public static String errorUpdateMessage(String description) {
		JSONObject obj = new JSONObject();
		try {
			obj.put("status", errorStatus);
			obj.put("message", errorUpdateMSG+" "+description);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return obj.toString();
	}
}
